package com.dididoctor.patient.Activity.DiagnosisDetails;

import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.dididoctor.patient.MV.EduActivity;
import com.dididoctor.patient.R;
import com.dididoctor.patient.Utils.LoaderImage;
import com.dididoctor.patient.Utils.UserHeadImage;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

import java.util.List;

/**
 * Created by liying on 2016/4/27.
 */
public class DiagnosisDetailsActivity extends EduActivity implements DiagnosisDetailsView {
    private ImageView mIvHead, mIvGender;
    private TextView mTvName, mTvAge, mTvDisease, mTvContent;
    private ListView mLvSuggest;
    private DiagnosisDetailsAdapter mAdapter;
    private DiagnosisDetailsPresenter mPresenter;
    private String recId;
    private String patientName;
    private String age;
    private String sex;
    private String illName;
    private String patientHeadPic;
    private UserHeadImage mImgUserimg;
    private LoaderImage loaderImage;
    private TextView mTvTitle;

    @Override
    public void init() {
        recId = getIntent().getStringExtra("recId");
        patientName = getIntent().getStringExtra("patientName");
        age = getIntent().getStringExtra("age");
        illName = getIntent().getStringExtra("illName");
        sex = getIntent().getStringExtra("sex");
        patientHeadPic = getIntent().getStringExtra("patientHeadPic");
        initView();
    }

    @Override
    public void onClickEvent(View view) {

    }

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_diagnosis_details);
    }

    private void initView() {
        mTvTitle = (TextView) findViewById(R.id.tv_title);
        mTvTitle.setText("诊疗建议详情");
        mImgUserimg = (UserHeadImage) findViewById(R.id.img_userimg);
        mIvGender = (ImageView) findViewById(R.id.iv_gender);
        if ("0".equals(sex)) {
            mIvGender.setImageResource(R.drawable.icon_girl);
        } else {
            mIvGender.setImageResource(R.drawable.icon_boy);
        }
        mTvName = (TextView) findViewById(R.id.tv_name);
        mTvName.setText(patientName);
        mTvAge = (TextView) findViewById(R.id.tv_age);
        mTvAge.setText(age);
        mTvDisease = (TextView) findViewById(R.id.tv_disease);
        mTvDisease.setText(illName);
        mTvContent = (TextView) findViewById(R.id.tv_content);
        mLvSuggest = (ListView) findViewById(R.id.lv_suggest);

        loaderImage = new LoaderImage(DiagnosisDetailsActivity.this);
        loaderImage.load(mImgUserimg, patientHeadPic, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {
                mImgUserimg.setImageResource(R.drawable.img_doctordefault);
            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {
                mImgUserimg.setImageResource(R.drawable.img_doctordefault);
            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {

            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });


        mPresenter = new DiagnosisDetailsPresenter(DiagnosisDetailsActivity.this, DiagnosisDetailsActivity.this);
        mPresenter.getInquiryDetails(recId);
    }

    @Override
    public void fillData(List<DiagnosisDetailsBean> data, String content) {
        mTvContent.setText(content);
        mAdapter = new DiagnosisDetailsAdapter(DiagnosisDetailsActivity.this, data);
        mLvSuggest.setAdapter(mAdapter);
    }

    @Override
    public void getDataFail() {

    }
}
